package com.zhaojiu.example.webservice.impl;

import com.zhaojiu.example.pojo.Content;
import com.zhaojiu.example.pojo.Person;
import com.zhaojiu.example.pojo.RequestTestBo;
import com.zhaojiu.example.webservice.WeatherWebService;
import org.springframework.util.CollectionUtils;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import java.util.Arrays;
import java.util.List;


@WebService(
        targetNamespace="http://service.cn_lc",
        name="WeatherWSSoap",
        portName="WeatherWSSoapPort",
        serviceName="WeatherWS"
)
public class WeatherInterfaceImpl implements WeatherWebService {
    @WebMethod(
            operationName="getWeather"
    )
    @Override
    public @WebResult(name="resultWeather")String queryWeather(@WebParam(name="cityName")String cityName,
                                                               @WebParam(name= "date")String date) {
        System.out.println("form client ..." + cityName);
//        System.out.println("form client ..." + person.getAge());
        return cityName + ":"+date;
    }

    @WebMethod(
            operationName="getPerson"
    )
    @Override
    public @WebResult(name="resultPerson") String queryPerson(@WebParam(name = "person") List<Person> persons) {

        if (!CollectionUtils.isEmpty(persons)){
            System.out.println("form client ..." + persons.size());
             for (Person person : persons) {
                 System.out.println("form client ..." + person.getAge());
                 System.out.println("form client ..." + person.getName());
             }
        }

        return Arrays.toString(persons.toArray());
    }


    /**
     * 入参 格式1   xml格式入参
     * @param xml
     * @return
     */
    @WebMethod(
            operationName="exchange2",
            exclude=false
    )
    @Override
    public @WebResult(name="resultString") String exchange2(@WebParam(name = "in0") String xml) {
        System.out.println("form client ...\n" + xml);
        return xml;
    }

    /**
     * 入参 格式2   json格式入参
     * @param json
     * @return
     */
    @WebMethod(
            operationName = "interfaceService",
            exclude = false
    )
    @Override
    public @WebResult(name = "interfaceServiceResponse") String json(@WebParam(name = "requestMsg") String json) {
        System.out.println("form client ...\n" + json);
        return json;
    }

    /**
     * 入参 格式3   对象格式入参
     * @param content
     * @return
     */
    @WebMethod(
            operationName = "callWebService",
            exclude = false
    )
    @Override
    public @WebResult(name = "result") String callWebService(@WebParam(name = "requMessage") Content content) {
        if (content != null){
            System.out.println("form client ...\n" + content.getConnectId());
            System.out.println("form client ...\n" + content.getContent());
            System.out.println("form client ...\n" + content.getPasswd());
            System.out.println("form client ...\n" + content.getSrvFunction());
            System.out.println("form client ...\n" + content.getSrvModule());
        }
        return null;
    }

    /**
     * 入参 格式4   集合格式入参
     * @param
     * @return
     */
    public String test4(String string){
        return null;
    }

    /**
     * 入参 格式5 复杂格式入参
     * @param requestTestBo
     * @return
     */
    @WebMethod(
            operationName = "UamPassUtil",
            exclude = false
    )
    @Override
    public @WebResult(name = "result") String test5(@WebParam(name = "requestinfo") RequestTestBo requestTestBo) {
        System.out.println(requestTestBo);
        return requestTestBo.getRequestXML();
    }
}
